<?php
class ressourcetype{
	protected $id,$name;

	function __construct($id,$name){
		$this->id = $id;
		$this->name = $name;
	}
	
	public function getId(){
		return $this->id;
	}

	public function getName(){
		return $this->name;	
	}
	
	public static function generateOption($default){
		$result = self::getAllRessourceType();
		while($row = $result->fetch_assoc()){
			$temp = new ressourcetype($row['id'],$row['name']);
			$str = $str."<option name=\"".$temp->getId()."\" value=\"".$temp->getId()."\"";
			if($default == $temp->getId()){
				$str = $str." selected=selected ";
			}
			$str = $str.">".$temp->getName()."</option>";
			unset($temp);
		}
		return $str;
	}
		
	public static function getAllRessourceType(){
		$conn = new dbmodifier();
		$query = "SELECT * FROM RESSOURCETYPE";
		$result = $conn->updateSQL($query);
		$conn->execute();
		return $result;
	}
	
	public static function getRessourceTypeByName($name){
		$conn = new dbmodifier();
		$name = $conn->db_connection->real_escape_string($name);
		$query = "SELECT * FROM ressourcetype WHERE name='".$name."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new ressourcetype($row['id'],$row['name']);		
		return $var;	

	}

	public static function getRessourceTypeById($id){
		$conn = new dbmodifier();
		$id = $conn->db_connection->real_escape_string($id);
		$query = "SELECT * FROM ressourcetype WHERE id='".$id."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new ressourcetype($row['id'],$row['name']);		
		return $var;	

	}
}
?>